const express = require('express')
const app = express()

const joi = require('joi')

const cors = require('cors')
app.use(cors())

app.use(express.json())
app.use(express.urlencoded({ extended: false }))

const passport = require('passport')
app.use(passport.initialize());
require('./config/passport')(passport)

const users = require('./routes/users')
app.use('/api/users', users)

const employees = require('./routes/employees')
app.use('/api/employees', employees)

const role = require('./routes/role')
app.use('/api/role', role)

const notices = require('./routes/notices')
app.use('/api/notices', notices)

app.post('/test', (req,res) => res.json('ok'))//test


app.use((err, req, res, next) => {
    if (err instanceof joi.ValidationError) return res.json({status: 1, message: err.message})
    res.json({
        status: 1,
        message: err.message
    })
})

const port = 5000

app.listen(port, () => console.log('server running on port 5000'))